<?php defined( '_VALID_MOS' ) or die( include("404.php") );

switch($_POST["hidden"])
{

	case "";
	// khoi dau trang khong co gia tri submit. khong lam zi ca
	break;
	
	case "submit_com_contact_view";
		if($_POST["task"] == "remove"){
			$check = FALSE;
			$values = $_POST["cid"];
			$myprocess = new process;
			for ($row = 0; $row < count($values); $row++){
				if($myprocess->process_remove_contact($values[$row]) <> FALSE)
				$check = TRUE;
			}
			if($check == TRUE){
				//$core_class->_redirect(".?com=com_contact&view=reply&msg=0");
			} else {
				$core_class->_redirect(".?com=com_contact&msg=Đã có lỗi xả ra, vui lòng thử lại!");
			}
		}
	break;
	
	case "reply_contact";
		if(isset($_POST["sendmailBtn"])){
			$myprocess = new process;
			if($myprocess->process_reply_contact("sadicocantho@hcm.vnn.vn" , $_POST["txttieude"], $_POST["txtnoidung"], $_POST["mailTo"]) <> FALSE){
				$core_class->_redirect(".?com=com_contact&view=reply&id=".$_POST["id"]."&msg=email của bạn đã được gửi thành công !");
			} else {
				$core_class->_redirect(".?com=com_contact&view=reply&msg=Đã có lỗi xả ra, vui lòng thử lại !");
			}
		}
	break;
	
	default:
		$core_class->_redirect(".");exit();
	break;
}

class process{

	// ham su ly go bo thong tin lien he
	function process_remove_contact($values){
		include("../protected/dbconnect.php");
		$sql = "Delete from contact where Id = ?";
		$cmd = $mysqli->prepare($sql);
		$cmd->bind_param("s", $values);
		if($cmd->execute() <> FALSE) return true;
		else echo $mysqli->error;
		$cmd->close();
		$mysqli->close();
	}
	
	// ham su ly go bo thong tin lien he
	function process_reply_contact( $from, $subject, $content, $to ){
		require_once('../htmlMimeMail5/htmlMimeMail5.php');
    
		$mail = new htmlMimeMail5();
	
		/**
		* Set the from address
		*/
		$mail->setFrom('sadico Reply <$from>');
		
		/**
		* Set the subject
		*/
		$mail->setSubject($subject);
		
		/**
		* Set high priority
		*/
		$mail->setPriority('high');
	
		/**
		* Set the text of the Email
		*/
		//$mail->setText('Sample text');
		
		/**
		* Set the HTML of the email
		*/
		$mail->setHTML($content);
		
		/**
		* Add an embedded image
		*/
		//$mail->addEmbeddedImage(new fileEmbeddedImage('background.gif'));
		
		/**
		* Add an attachment
		*/
		//$mail->addAttachment(new fileAttachment('example.zip'));
	
		/**
		* Send the email
		*/
		$mail->send(array($to));
		
		return true;
	}
	
}